#pragma once
#include "afxcmn.h"

#include "UICtrl/TVector.h"
#include "ExtListHeadCtrl.h"
#include "UICtrl/ComScrollBarCtrl/ComScrollBar.h"
#include "UICtrl/ComScrollBarCtrl/ComScrollBarCtrl.h"
struct  SListItemProp
{
	int			nRow;
	int			nCol;
	BOOL		bCombobox;
	SListItemProp()
	{
		nRow		= -1;
		nCol		= -1;
		bCombobox	= FALSE;
	}
};

struct  SListItemColor
{
	int			nRow;
	int			nCol;
	COLORREF	clrItem;
	COLORREF	clrText;
	SListItemColor()
	{
		nRow		= -1;
		nCol		= -1;
		clrItem		= RGB(44, 51, 69);
		clrText		= RGB(255, 255, 255);
	}
};
struct  SListAllRowColor
{
	int			nRow;
	COLORREF	clrAllRow;
	COLORREF	clrText;
	SListAllRowColor()
	{
		nRow		= -1;
		clrAllRow	= RGB(44, 51, 69);
		clrText		= RGB(255, 255, 255);
	}
};
struct  SListAllColColor
{
	int			nCol;
	COLORREF	clrAllCol;
	COLORREF	clrText;
	SListAllColColor()
	{
		nCol		= -1;
		clrAllCol	= RGB(44, 51, 69);
		clrText		= RGB(255, 255, 255);
	}
};

class CExtListCtrl : public CListCtrl
{
public:
	CExtListCtrl(void);
	~CExtListCtrl(void);

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if (WM_KEYDOWN == pMsg->message && (VK_RETURN == pMsg->wParam || VK_ESCAPE == pMsg->wParam))
		{
			pMsg->message = WM_KILLFOCUS;
		}
		return CListCtrl::PreTranslateMessage(pMsg);
	}

public:
	virtual void PreSubclassWindow();
	virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg void OnPaint();
	afx_msg void OnNcPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
 	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
 	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	DECLARE_MESSAGE_MAP()
public:	
	void	GetEveryItemRect(int nRow, int nCol, int nArea, CRect& rect);					//获取LIST任何一个单元格的矩形
	INT		GetColumnCount();
	//设置表头
	void	ReplaceHeader();																//替换表头
	void	SetHeaderHeight(int nHeaderHeight);
	void	SetHeaderBkColor(COLORREF clrHeaderBk);
	void	SetHeaderTextColor(COLORREF clrHeaderText);
	void    SetHeaderBorder(BOOL bEnableBorder, COLORREF clrHeadBorder, UINT nPixel); 
	void	SetHeaderFont(int nFontHeight, BOOL bBold = FALSE);
	//设置表内容
	void	SetListGrid(BOOL bEnableGrid, COLORREF clrDivLine);
	void	SetListBorder(BOOL bEnableBorder, COLORREF clrBorder);
	void	SetItemHeight(int nHeight);														//设置行高
	void	SetListBkColor(COLORREF clrListBk);												//设置列表背景颜色	
	void	SetListTextColor(COLORREF clrListText);											//设置列表文本颜色	
	void	SetItemColor(int nRow, int nCol, COLORREF clrText, COLORREF clrItemBk);	
	void	SetItemCombobox(int nRow, int nCol, BOOL bCombobox);	
	void	SetAllRowColor(COLORREF clrItemBk,  COLORREF clrText, int nRow);				
	void	SetAllColColor(COLORREF clrItemBk, COLORREF clrText, int nCol);					
	void	SetSelRowColor(COLORREF clrSelRowBk, COLORREF clrSelRowText);					
	void	SetEnableBorder(BOOL EnableBorder = TRUE);										
	void	SetFont(int nFontHeight, BOOL bBold = FALSE);

	BOOL	DeleteAllItems();
	BOOL	DeleteItem(int nItem);
	BOOL	DeleteColumn(int nCol);
	BOOL	GetItemColor(int nRow,int nCol, COLORREF& clrText, COLORREF& clrItemBk);
private:
	void	FindItemColor(int nRow, int nCol, COLORREF& clrItemBk, COLORREF& clrItemText);
	void	FindItemProp(int nRow, int nCol, BOOL& bCombobox);
	void	DrawListItemText(CDC *pDC, int nItem, int nSubItem, CRect rcItem, COLORREF clrText, BOOL bCombobox);
	void	DrawGridLine(CDC *pDC, int nItemID);
	void	DrawBorder(CDC *pDC);
	void	DrawAllow( CDC *pDC, CRect rect, COLORREF clrAllow );

protected:
	TVECTOR <SListItemProp*>			m_vectorProps;
	TVECTOR <SListItemColor*>			m_vectorClrItem;
	TVECTOR <SListAllColColor*>			m_vectorClrAllCol;
	TVECTOR <SListAllRowColor*>			m_vectorClrAllRow;
	CExtListHeadCtrl					m_listHeader;				//自定义表头的变量
	COLORREF							m_clrItemBk;				//单元格背景颜色
	COLORREF							m_clrListBk;				//list列表背景颜色
	COLORREF							m_clrListText;				//list列表字体颜色
	COLORREF							m_clrSelRowBk;				//选中行时高亮颜色
	COLORREF							m_clrSelRowText;			//选中行的字体颜色
	COLORREF							m_clrGridLine;				//分隔线颜色
	COLORREF							m_clrBorder;				//边框颜色
	int									m_nRowHeight;				//行高
	BOOL								m_bEnableGrid;				//是否画栅格
	BOOL								m_bEnableBorder;			//是否画边框

	CFont								m_fontText;

	CComScrollBarCtrl					m_HScroll;
	CComScrollBarCtrl					m_VScroll;

	int									m_nDrawItemOffset;	
    int                                 m_iAllItemHeight;
    int                                 m_iItemWidth;
};	

